package com.iecas.xxx.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iecas.xxx.model.Demo;
import com.iecas.xxx.mapper.DemoMapper;
import com.iecas.xxx.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * Demo表 服务实现类
 * </p>
 *
 * @author iecas
 * @since 2021-09-14
 */
@Service
public class DemoServiceImpl extends ServiceImpl<DemoMapper, Demo> implements DemoService {

    @Autowired
    private DemoMapper demoMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public IPage<Demo> getDemosByPage(Integer pageNum, Integer pageSize) {
        // 参数一是当前页，参数二是每页个数
        IPage<Demo> demoPage = new Page<>(pageNum, pageSize);
        demoPage = demoMapper.selectPage(demoPage, null);
        return demoPage;
    }

    @Override
    public void cacheDemos() {
        List<Demo> demos = demoMapper.selectList(null);
        redisTemplate.opsForValue().set("demoList", demos);
    }
}
